package com.pureut.order.service.impl;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.core.exception.GlobalException;
import com.pureut.common.core.utils.bean.BeanUtils;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.datascope.annotation.DataScope;
import com.pureut.common.security.utils.DictUtils;
import com.pureut.common.security.utils.SecurityUtils;
import com.pureut.order.domain.ConverterManagement;
import com.pureut.order.domain.PublicGoods;
import com.pureut.order.domain.SubcontractingOrder;
import com.pureut.order.domain.SubcontractingOrderMaterialDetail;
import com.pureut.order.dto.*;
import com.pureut.order.mapper.PublicGoodsMapper;
import com.pureut.order.mapper.SalesOrderMapper;
import com.pureut.order.mapper.SubcontractingOrderMapper;
import com.pureut.order.mapper.SubcontractingOrderMaterialDetailMapper;
import com.pureut.order.service.ConverterManagementService;
import com.pureut.order.service.SubcontractingOrderMaterialDetailService;
import com.pureut.order.service.SubcontractingOrderService;
import com.pureut.order.vo.BackDataVo;
import com.pureut.order.vo.UpdateSubcontractingOrderDataVo;
import com.pureut.order.vo.*;
import com.pureut.system.api.FeignService;
import com.pureut.system.api.OrderFeignService;
import com.pureut.system.api.SchedulingPlanFeignService;
import com.pureut.system.api.StorageFegin;
import com.pureut.system.api.domain.SysDictData;
import com.pureut.system.api.dto.SchedulingPlanDto;
import com.pureut.system.api.vo.*;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.*;
import java.util.stream.Collectors;

//import com.pureut.order.vo.SubcontractingOrderMaterialDetailVo;
//import com.pureut.system.api.vo.SubcontractingOrderMaterialDetailVo;

/***
 *
 * Author:C
 * Date:2022/12/02 9:58
 * @DESC
 */
@Service
public class SubcontractingOrderServiceImpl extends ServiceImpl<SubcontractingOrderMapper, SubcontractingOrder> implements SubcontractingOrderService {

    @Resource
    SubcontractingOrderMapper subcontractingOrderMapper;

    @Resource
    FeignService feignService;

    @Resource
    SchedulingPlanFeignService schedulingPlanFeignService;

    @Resource
    PublicGoodsMapper publicGoodsMapper;

    @Resource
    StorageFegin storageFegin;

    @Resource
    OrderFeignService orderFeignService;

    //销售订单修改
    @Resource
    SalesOrderMapper salesOrderMapper;


    @Lazy
    @Resource
    SubcontractingOrderMaterialDetailService subcontractingOrderMaterialDetailService;

    @Lazy
    @Resource
    SubcontractingOrderMaterialDetailMapper subcontractingOrderMaterialDetailMapper;

    @Resource
    ConverterManagementService converterManagementService;

    /**
     * 委外订单列表
     *
     * @param subcontractingOrderVo
     * @return
     */
    @Override
    @DataScope(deptAlias = "a")
    public List<SubcontractingOrderDto> getList(SubcontractingOrderVo subcontractingOrderVo) {
        //获取委外订单列表
        List<SubcontractingOrderDto> subcontractingOrderList = subcontractingOrderMapper.getSubcontractingOrderList(subcontractingOrderVo);
        //获取委外订单状态缓存字典数据
        List<SysDictData> array = DictUtils.getDictCache("subcontracting_order_status");
        Map<String, String> actualMap = array.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        //获取网型字典数据
        List<SysDictData> typeArray = DictUtils.getDictCache("sys_of_type");
        Map<String, String> typeMap = typeArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        //获取铺网类型字典数据
        List<SysDictData> typeNetArray = DictUtils.getDictCache("sys_type_net");
        Map<String, String> typeNetMap = typeNetArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        //单位
        List<SysDictData> unit = DictUtils.getDictCache("sys_material_unit");
        Map<String, String> unitMap = unit.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        for (SubcontractingOrderDto entity : subcontractingOrderList) {
            entity.setMaterialUnitDict(unitMap.get(entity.getMaterialUnit()));
            entity.setStatusDict(actualMap.get(entity.getStatus()));
            entity.setMaterialNetDict(typeMap.get(entity.getMaterialNet()));
            entity.setMaterialNetTypeDict(typeNetMap.get(entity.getMaterialNetType()));
        }
        return subcontractingOrderList;
    }


    /**
     * 新增委外订单
     *
     * @param subcontractingOrderVo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveSubcontractingOrder(SubcontractingOrderVo subcontractingOrderVo) throws Exception {
        //保存委外订单信息
        SubcontractingOrder subcontractingOrder = new SubcontractingOrder();
        BeanUtils.copyProperties(subcontractingOrderVo, subcontractingOrder);
        String authorityCoding = feignService.getAuthorityCoding("order:subcontracting:order:list");
        if (authorityCoding == null) {
            throw new GlobalException("未进行单据配置,单据编码生成失败");
        }
        subcontractingOrder.setCreateBy(SecurityUtils.getUsername())
                .setDeptId(SecurityUtils.getDeptId())
                .setCreateTime(new Date())
                .setCreateBy(SecurityUtils.getUsername())
                .setStatus(1)
                .setSubcontractingOrderNum(authorityCoding)
                .setMaterialType(Integer.parseInt(subcontractingOrderVo.getMaterialType()))
                .setSubType(subcontractingOrderVo.getSubcontractingType())
                .setThickness(subcontractingOrderVo.getThickness())
                .setAssociatedDocNum(subcontractingOrderVo.getAssociatedDocNum());
        boolean save = save(subcontractingOrder);
        if (save) {
            //保存物料明细信息
            List<com.pureut.order.vo.SubcontractingOrderMaterialDetailVo> materialDetailList = subcontractingOrderVo.getMaterialDetailList();
            List<SubcontractingOrderMaterialDetail> orderMaterialDetail = new ArrayList<>();
            try {
                if (materialDetailList.size() > 0) {
                    for (com.pureut.order.vo.SubcontractingOrderMaterialDetailVo entity : materialDetailList) {
                        SubcontractingOrderMaterialDetail subcontractingOrderMaterialDetail = new SubcontractingOrderMaterialDetail();
                        subcontractingOrderMaterialDetail.setMaterialId(subcontractingOrderVo.getMaterialId())
                                .setBomCode(subcontractingOrderVo.getBomCode())
                                .setBomDetailDosage(entity.getBomProportion())
                                .setBomId(entity.getBomId())
                                .setMaterialType(entity.getBomType())
                                .setMaterialCode(entity.getMaterialCode())
                                .setSubcontractingOrderId(subcontractingOrder.getId())
                                .setWarehouseWeight(entity.getWarehouseWeight())
                                .setMaterialUnit(entity.getMaterialUnit());
                        orderMaterialDetail.add(subcontractingOrderMaterialDetail);
                    }
                    return subcontractingOrderMaterialDetailService.saveBatch(orderMaterialDetail);
                } else {
                    throw new GlobalException("请至少选择一个物料");
                }
            } catch (Exception e) {
                throw new SQLException("批量保存失败");
            }
        }
        return save;
    }

    /**
     * 提交审核
     *
     * @param id
     * @return
     */
    @Override
    public boolean submitReview(Long id) {
        SubcontractingOrder subcontractingOrder = getById(id);
        if (subcontractingOrder.getStatus() == 1) {
            subcontractingOrder.setStatus(2);

            SysWorkbenchAuditAgentVo sysWorkbenchAuditAgentVo = new SysWorkbenchAuditAgentVo();
            sysWorkbenchAuditAgentVo.setDocConfig("order:subcontracting:order:review");
            sysWorkbenchAuditAgentVo.setReceiptName("委外订单");
            sysWorkbenchAuditAgentVo.setReceiptNumber(subcontractingOrder.getSubcontractingOrderNum());//
            sysWorkbenchAuditAgentVo.setStatus(1);//待审核
            sysWorkbenchAuditAgentVo.setReceiptContent("有单据待审核,请及时审核");

            feignService.insertAuditAgent(sysWorkbenchAuditAgentVo);

            return updateById(subcontractingOrder);
        } else {
            throw new GlobalException("只能操作待提交的单据");
        }

    }

    /**
     * 上传合同
     *
     * @param subcontractingOrderUploadContractVo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean uploadContract(SubcontractingOrderUploadContractVo subcontractingOrderUploadContractVo) {
        SubcontractingOrder subcontractingOrder = getById(subcontractingOrderUploadContractVo.getId());
        if (7 == subcontractingOrder.getStatus() || 11 == subcontractingOrder.getStatus()) {
            //如果是合同未通过
            if (11 == subcontractingOrder.getStatus()) {
                //调用审核
                SysAuditHistoryVo sysAuditHistoryVo = new SysAuditHistoryVo();
                String perms = "order:subcontracting:order:contractReview";
                String auditDoc = subcontractingOrder.getSubcontractingContractNum();
                sysAuditHistoryVo.setAuditDoc(auditDoc);
                sysAuditHistoryVo.setPerms(perms);
                feignService.editHistory(sysAuditHistoryVo);

            }
            subcontractingOrder.setConverterId(subcontractingOrderUploadContractVo.getConverterId())
                    .setSubcontractingContractNum(subcontractingOrderUploadContractVo.getSubcontractingContractNum())
                    .setContractUrl(subcontractingOrderUploadContractVo.getContractUrl())
                    .setStatus(9);
            return updateById(subcontractingOrder);
//            //根据id获取明细表数据
//            SubcontractingOrderDetail subcontractingOrderDetail = subcontractingOrderDetailMapper.selectOne(new QueryWrapper<SubcontractingOrderDetail>().lambda().eq(SubcontractingOrderDetail::getSubcontractingOrderId, subcontractingOrderUploadContractVo.getId()));
//            subcontractingOrderDetail.setQualityStandard(Integer.parseInt(subcontractingOrderUploadContractVo.getQualityStandard()));
//            subcontractingOrderDetail.setArrivalTime(subcontractingOrderUploadContractVo.getArrivalTime());
//            subcontractingOrderDetail.setTotalExpenses(subcontractingOrderUploadContractVo.getTotalExpenses());
//            return subcontractingOrderDetailMapper.updateById(subcontractingOrderDetail) > 0;
        } else {
            throw new GlobalException("只能操作待签定、合同未通过的的委外订单");
        }
    }

    /**
     * 撤销审核
     *
     * @param id
     * @return
     */
    @Override
    public boolean deleteReview(Long id) {
        SubcontractingOrder subcontractingOrder = getById(id);
        if (2 == subcontractingOrder.getStatus()) {
            subcontractingOrder.setStatus(1);

            feignService.deleteDoc(subcontractingOrder.getSubcontractingOrderNum(), "委外订单");

            return updateById(subcontractingOrder);
        } else {
            throw new GlobalException("只能撤销待审核的订单");
        }
    }

    /**
     * 委外订单关结
     *
     * @param subcontractingOrderVo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean close(SubcontractingOrderVo subcontractingOrderVo) {
        //获取委外订单
        SubcontractingOrder subcontractingOrder = getById(subcontractingOrderVo.getId());
        if (subcontractingOrder.getStatus() == 5 || subcontractingOrder.getStatus() == 6) {
            throw new GlobalException("不能操作已完成、已关结的单据");
        }
//        if (1 == subcontractingOrder.getStatus() || 4 == subcontractingOrder.getStatus() || 11 == subcontractingOrder.getStatus()) {
        subcontractingOrder.setStatus(6);
        subcontractingOrder.setCloseReason(subcontractingOrderVo.getCloseReason());
        //修改委外入库单数据状态为关结
        UpdateReceiptStatusVo updateReceiptStatusVo = new UpdateReceiptStatusVo();
        updateReceiptStatusVo.setUpdateValue(5);
        updateReceiptStatusVo.setPurchaseOrderNo(subcontractingOrder.getSubcontractingOrderNum());
        storageFegin.updateSubcontractReceiptStatus(updateReceiptStatusVo);
        //修改委外发货单数据状态为关结
        PickingOutsourceFeignVo pickingOutsourceFeignVo = new PickingOutsourceFeignVo();
        pickingOutsourceFeignVo.setConnectionId(subcontractingOrder.getSubcontractingOrderNum());
        pickingOutsourceFeignVo.setCloseCause(subcontractingOrderVo.getCloseReason());
        storageFegin.closeOutsourceFeign(pickingOutsourceFeignVo);
        return updateById(subcontractingOrder);

    }

    /**
     * 查看委外订单信息
     *
     * @param id
     * @return
     */
    @Override
    public SubcontractingOrderDto getView(Long id) {
        SubcontractingOrderDto subcontractingOrderDto = new SubcontractingOrderDto();
        SubcontractingOrderDto subcontractingOrder = subcontractingOrderMapper.getViewById(id);
        BeanUtils.copyProperties(subcontractingOrder, subcontractingOrderDto);
        //类型字典值
        List<SysDictData> materialTypeArray = DictUtils.getDictCache("subcontracting_order_material_type");
        Map<String, String> materialType = materialTypeArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        subcontractingOrderDto.setMaterialType(String.valueOf(subcontractingOrder.getMaterialType()));
        subcontractingOrderDto.setMaterialTypeDict(materialType.get(String.valueOf(subcontractingOrder.getMaterialType())));
        List<SysDictData> array = DictUtils.getDictCache("subcontracting_order_status");
        Map<String, String> actualMap = array.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        //委外类型
        List<SysDictData> subTypeArray = DictUtils.getDictCache("subcontracting_order_type");
        Map<String, String> subTypeMap = subTypeArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        //状态
        subcontractingOrderDto.setStatus(String.valueOf(subcontractingOrder.getStatus()));
        subcontractingOrderDto.setStatusDict(actualMap.get(String.valueOf(subcontractingOrder.getStatus())));
        //加工商
        ConverterManagement converterManagement = converterManagementService.getById(subcontractingOrder.getConverterId());
        if (converterManagement != null) {
            subcontractingOrderDto.setConverterDict(converterManagement.getConverterName());
        }
        //获取物料类型字典数据
        List<SysDictData> typeArray = DictUtils.getDictCache("subcontracting_order_material_type");
        Map<String, String> typeMap = typeArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        subcontractingOrderDto.setMaterialTypeDict(typeMap.get(subcontractingOrderDto.getMaterialType()));

        //获取委外订单物料明细信息
        List<SubcontractingOrderMaterialDetailDto> subcontractingOrderMaterialDetailView = subcontractingOrderMaterialDetailMapper.getSubcontractingOrderMaterialDetailView(id);

        //获取单位字典数据
        List<SysDictData> unitArray = DictUtils.getDictCache("sys_material_unit");
        Map<String, String> unitMap = unitArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        for (SubcontractingOrderMaterialDetailDto entity : subcontractingOrderMaterialDetailView) {
            entity.setMaterialUnitDict(unitMap.get(String.valueOf(entity.getMaterialUnit())));
            String materialCode = entity.getMaterialCode();
            //获取对应物料库存量
            double stockWeight = storageFegin.getStockWeight(entity.getMaterialCode());
            entity.setStockWeight(stockWeight);
            if ("1".equals(entity.getMaterialType())) {
                //获取原料信息
                //类型
                entity.setMaterialTypeDict("原料");
                AjaxResult awmateriaViewByMaterialCode = feignService.getAwmateriaViewByMaterialCode(materialCode);
                MaterialAwmateriaDto data = JSON.parseObject(JSON.toJSONString(awmateriaViewByMaterialCode.get("data")), MaterialAwmateriaDto.class);
                //类别
                entity.setMaterialCategoryDict(data.getMaterialCategory());
            }
            // 半成品：3
            if ("3".equals(entity.getMaterialType())) {
                //类型
                entity.setMaterialTypeDict("半成品");
                //获取半成品信息
                AjaxResult halfViewByMaterialCode = feignService.getHalfViewByMaterialCode(materialCode);
                MaterialHalfDto data = JSON.parseObject(JSON.toJSONString(halfViewByMaterialCode.get("data")), MaterialHalfDto.class);
                //类别
                entity.setMaterialCategoryDict(data.getMaterialCategory());
            }
            //辅料：2
            if ("2".equals(entity.getMaterialType())) {
                //类型
                entity.setMaterialTypeDict("辅料");
                //获取半成品信息
                AjaxResult halfViewByMaterialCode = feignService.getAccessoriesViewByMaterialCode(materialCode);
                MaterialAwmateriaDto data = JSON.parseObject(JSON.toJSONString(halfViewByMaterialCode.get("data")), MaterialAwmateriaDto.class);
                //类别
                entity.setMaterialCategoryDict(data.getMaterialCategory());
            }

            //成品:4
            if ("4".equals(entity.getMaterialType())) {
                //类型
                entity.setMaterialTypeDict("成品");
                //获取半成品信息
                AjaxResult halfViewByMaterialCode = feignService.getFinishViewByMaterialCode(materialCode);
                MaterialFinishedDto data = JSON.parseObject(JSON.toJSONString(halfViewByMaterialCode.get("data")), MaterialFinishedDto.class);
                //类别
                entity.setMaterialCategoryDict(data.getMaterialCategory());
            }

        }
        subcontractingOrderDto.setOrderMaterialDetailList(subcontractingOrderMaterialDetailView);

        //委外类型
        subcontractingOrderDto.setSubcontractingTypeDict(subTypeMap.get(subcontractingOrderDto.getSubcontractingType()));

        return subcontractingOrderDto;
    }

    /**
     * 修改
     *
     * @param subcontractingOrderUpdateVo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateSubcontractingOrder(SubcontractingOrderUpdateVo subcontractingOrderUpdateVo) throws SQLException {

        //获取委外订单信息
        SubcontractingOrder subcontractingOrder = getById(subcontractingOrderUpdateVo.getId());
        //是否为合同未通过
        boolean status1 = 11 == subcontractingOrder.getStatus();
        //是否为待提交
        boolean status2 = 1 == subcontractingOrder.getStatus();
        //是否为订单未通过
        boolean status3 = 4 == subcontractingOrder.getStatus();
        if (status2 || status3) {
            subcontractingOrder.setMaterialType(Integer.parseInt(subcontractingOrderUpdateVo.getMaterialType()))
                    .setBomCode(subcontractingOrderUpdateVo.getBomCode())
                    .setAssociatedDocNum(subcontractingOrderUpdateVo.getAssociatedDocNum())
                    .setSubcontractingWeight(subcontractingOrderUpdateVo.getSubcontractingWeight())
                    .setDemandTime(subcontractingOrderUpdateVo.getDemandTime());

            //将原来的物料明细删除，再将新的物料明细信息存入
            List<SubcontractingOrderMaterialDetail> subcontractingOrderMaterialDetails = subcontractingOrderMaterialDetailMapper.selectList(new QueryWrapper<SubcontractingOrderMaterialDetail>().lambda().eq(SubcontractingOrderMaterialDetail::getSubcontractingOrderId, subcontractingOrder.getId()));
            subcontractingOrderMaterialDetailService.removeBatchByIds(subcontractingOrderMaterialDetails);
            //获取传入的物料明细列表
            List<com.pureut.order.vo.SubcontractingOrderMaterialDetailVo> materialDetailList = subcontractingOrderUpdateVo.getOrderMaterialDetailList();
            List<SubcontractingOrderMaterialDetail> list = new ArrayList<>();

            if (materialDetailList.size() > 0) {
                for (com.pureut.order.vo.SubcontractingOrderMaterialDetailVo entity : materialDetailList) {
                    SubcontractingOrderMaterialDetail subcontractingOrderMaterialDetail = new SubcontractingOrderMaterialDetail();
                    subcontractingOrderMaterialDetail.setMaterialId(subcontractingOrderUpdateVo.getMaterialId())
                            .setMaterialCode(entity.getMaterialCode())
                            .setBomDetailDosage(entity.getBomDetailDosage())
                            .setBomId(entity.getBomId())
                            .setMaterialType(Integer.parseInt(entity.getMaterialType()))
                            .setMaterialUnit(entity.getMaterialUnit())
                            .setBomCode(subcontractingOrderUpdateVo.getBomCode())
                            .setSubcontractingOrderId(subcontractingOrder.getId())
                            .setWarehouseWeight(entity.getWarehouseWeight());
                    list.add(subcontractingOrderMaterialDetail);
                }
            }
            //调用审核
            if (4 == subcontractingOrder.getStatus()) {
                SysAuditHistoryVo sysAuditHistoryVo = new SysAuditHistoryVo();
                String perms = "order:subcontracting:order:review";
                String auditDoc = subcontractingOrder.getSubcontractingOrderNum();
                sysAuditHistoryVo.setAuditDoc(auditDoc);
                sysAuditHistoryVo.setPerms(perms);
                AjaxResult history = feignService.editHistory(sysAuditHistoryVo);
                String data = JSON.parseObject(JSON.toJSONString(history.get("msg")), String.class);
                if ("操作成功".equals(data)) {
                    subcontractingOrder.setStatus(1);
                    updateById(subcontractingOrder);

                    //修改审核代办状态为已处理
                    feignService.updateStatus(3, subcontractingOrder.getSubcontractingOrderNum(), "委外订单");//

                    return subcontractingOrderMaterialDetailService.saveBatch(list);
                } else {
                    return false;
                }
            }
            updateById(subcontractingOrder);
            return subcontractingOrderMaterialDetailService.saveBatch(list);
        } else if (status1) {
            subcontractingOrder.setConverterId(subcontractingOrderUpdateVo.getConverterId())
                    .setSubcontractingContractNum(subcontractingOrderUpdateVo.getSubcontractingContractNum())
                    .setContractUrl(subcontractingOrderUpdateVo.getContractUrl());

            //调用审核
            SysAuditHistoryVo sysAuditHistoryVo = new SysAuditHistoryVo();
            String perms = "order:subcontracting:order:contractReview";
            String auditDoc = subcontractingOrder.getSubcontractingContractNum();
            sysAuditHistoryVo.setAuditDoc(auditDoc);
            sysAuditHistoryVo.setPerms(perms);
            AjaxResult history = feignService.editHistory(sysAuditHistoryVo);
            String data = JSON.parseObject(JSON.toJSONString(history.get("msg")), String.class);
            if ("操作成功".equals(data)) {
                subcontractingOrder.setStatus(9);
                return updateById(subcontractingOrder);
            } else {
                return false;
            }
        } else {
            throw new GlobalException("只能修改合同未通过、待提交、订单未通过状态的数据");
        }
    }


    /**
     * 订单审核
     *
     * @param orderReviewVo
     * @return
     */
    @Override
    public boolean orderReview(OrderReviewVo orderReviewVo) {
        SubcontractingOrder subcontractingOrder = getById(orderReviewVo.getId());
        if (subcontractingOrder.getStatus() == 2 || subcontractingOrder.getStatus() == 3) {
            String perms = "order:subcontracting:order:review";
            int isAdopt = orderReviewVo.getIsAdopt();
            String auditDoc = subcontractingOrder.getSubcontractingOrderNum();
            String auditRemarks = orderReviewVo.getReviewComments();
            Long userId = SecurityUtils.getUserId();
            AjaxResult sequence = feignService.getSequenceTwo(perms, 2, isAdopt, auditRemarks, auditDoc, userId);
            Integer data = JSON.parseObject(JSON.toJSONString(sequence.get("data")), Integer.class);
            if (data == null) {
                throw new GlobalException("未对该审核进行配置");
            }
            //1:通过，2：审核中，3：没权限 4:该人已经审核过
            if (orderReviewVo.getIsAdopt() == 1) {
                if (data == 1) {
                    subcontractingOrder.setStatus(7);
                    if (subcontractingOrder.getReviewedBy() == null) {
                        subcontractingOrder.setReviewedBy(SecurityUtils.getUsername());
                    } else {
                        subcontractingOrder.setReviewedBy(subcontractingOrder.getReviewedBy() + "," + SecurityUtils.getUsername());
                    }
                    subcontractingOrder.setReviewedTime(new Date());

                    feignService.updateStatus(3, subcontractingOrder.getSubcontractingOrderNum(), "委外订单");

                    return updateById(subcontractingOrder);
                } else if (data == 2) {
                    subcontractingOrder.setStatus(3);
                    if (subcontractingOrder.getReviewedBy() == null) {
                        subcontractingOrder.setReviewedBy(SecurityUtils.getUsername());
                    } else {
                        subcontractingOrder.setReviewedBy(subcontractingOrder.getReviewedBy() + "," + SecurityUtils.getUsername());
                    }
                    subcontractingOrder.setReviewedTime(new Date());
                    return updateById(subcontractingOrder);
                } else if (data == 3) {
                    throw new GlobalException("没有审核权限");
                } else {
                    throw new GlobalException("该用户已经审核过");
                }
            } else {
                if (data == 1 || data == 2) {
                    subcontractingOrder.setStatus(4);
                    if (subcontractingOrder.getReviewedBy() == null) {
                        subcontractingOrder.setReviewedBy(SecurityUtils.getUsername());
                    } else {
                        subcontractingOrder.setReviewedBy(subcontractingOrder.getReviewedBy() + "," + SecurityUtils.getUsername());
                    }
                    subcontractingOrder.setReviewedTime(new Date());

                    SysWorkbenchAuditAgentVo sysWorkbenchAuditAgentVo = new SysWorkbenchAuditAgentVo();
                    sysWorkbenchAuditAgentVo.setDocConfig("order:subcontracting:order:review");
                    sysWorkbenchAuditAgentVo.setReceiptName("委外订单");
                    sysWorkbenchAuditAgentVo.setReceiptNumber(subcontractingOrder.getSubcontractingOrderNum());//
                    sysWorkbenchAuditAgentVo.setStatus(2);//待处理

                    sysWorkbenchAuditAgentVo.setPassFlag("1");
                    sysWorkbenchAuditAgentVo.setCreateName(subcontractingOrder.getCreateBy());

                    sysWorkbenchAuditAgentVo.setReceiptContent("有单据未通过,请及时查看");

                    feignService.insertAuditAgent(sysWorkbenchAuditAgentVo);

                    return updateById(subcontractingOrder);
                } else if (data == 3) {
                    throw new GlobalException("没有审核权限");
                } else {
                    throw new GlobalException("该用户已经审核过");
                }
            }

        } else {
            throw new GlobalException("状态为待审核和审核中的单据才能进行审核");
        }
    }

    /**
     * 合同审核
     *
     * @param orderReviewVo
     * @return
     */
    @Override
    public boolean contractReview(OrderReviewVo orderReviewVo) {
        SubcontractingOrder subcontractingOrder = getById(orderReviewVo.getId());
        if (subcontractingOrder.getStatus() == 9 || subcontractingOrder.getStatus() == 10) {
            String perms = "order:subcontracting:order:contractReview";
            int isAdopt = orderReviewVo.getIsAdopt();
            String auditDoc = subcontractingOrder.getSubcontractingContractNum();
            String auditRemarks = orderReviewVo.getReviewComments();
            Long userId = SecurityUtils.getUserId();
            AjaxResult sequence = feignService.getSequenceTwo(perms, 2, isAdopt, auditRemarks, auditDoc, userId);
            Integer data = JSON.parseObject(JSON.toJSONString(sequence.get("data")), Integer.class);
            if (data == null) {
                throw new GlobalException("未对该审核进行配置");
            }
            //1:通过，2：审核中，3：没权限 4:该人已经审核过
            if (orderReviewVo.getIsAdopt() == 1) {
                if (data == 1) {
                    //通过之后向委外出库和委外入库发送数据
                    sendData(subcontractingOrder);
                    subcontractingOrder.setStatus(8);
                    return updateById(subcontractingOrder);
                } else if (data == 2) {
                    subcontractingOrder.setStatus(10);
                    return updateById(subcontractingOrder);
                } else if (data == 3) {
                    throw new GlobalException("没有审核权限");
                } else {
                    throw new GlobalException("该用户已经审核过");
                }
            } else {
                if (data == 1 || data == 2) {
                    subcontractingOrder.setStatus(11);
                    return updateById(subcontractingOrder);
                } else if (data == 3) {
                    throw new GlobalException("没有审核权限");
                } else {
                    throw new GlobalException("该用户已经审核过");
                }
            }
        } else {
            throw new GlobalException("状态为“待合同审核”和“合同审核中”的单据才能进行审核");
        }
    }

    /**
     * 委外入库回传委外订单（fegin调用）
     *
     * @param updateSubcontractingOrderDataVo
     * @return
     */
    @Override
    public boolean updateSubcontractingOrderData(UpdateSubcontractingOrderDataVo updateSubcontractingOrderDataVo) {

        //修改明细对应出库量
        if (updateSubcontractingOrderDataVo.getOutWeight() != null) {
            //修改对应明细数据
            SubcontractingOrder subcontractingOrder = subcontractingOrderMapper.selectOne(new QueryWrapper<SubcontractingOrder>().lambda().eq(SubcontractingOrder::getSubcontractingOrderNum, updateSubcontractingOrderDataVo.getSubcontractingOrderNumber()));
            List<SubcontractingOrderMaterialDetail> subcontractingOrderDetails = subcontractingOrderMaterialDetailMapper.selectList(new QueryWrapper<SubcontractingOrderMaterialDetail>().lambda().eq(SubcontractingOrderMaterialDetail::getSubcontractingOrderId, subcontractingOrder.getId()));
            for (SubcontractingOrderMaterialDetail entity : subcontractingOrderDetails) {
                if (entity.getMaterialCode().equals(updateSubcontractingOrderDataVo.getMaterialCode())) {
                    if (entity.getOutWeight() == 0) {
                        entity.setOutWeight(updateSubcontractingOrderDataVo.getOutWeight());
                    } else {
                        BigDecimal add = new BigDecimal(String.valueOf(entity.getOutWeight())).add(new BigDecimal(String.valueOf(updateSubcontractingOrderDataVo.getOutWeight())));
                        entity.setOutWeight(Double.parseDouble(add.toString()));
                    }
                }
            }
            return subcontractingOrderMaterialDetailService.updateBatchById(subcontractingOrderDetails);
        }
        //修改单据退货重量
        if (updateSubcontractingOrderDataVo.getBackWeight() != null) {
            SubcontractingOrder subcontractingOrder = subcontractingOrderMapper.selectOne(new QueryWrapper<SubcontractingOrder>().lambda().eq(SubcontractingOrder::getSubcontractingOrderNum, updateSubcontractingOrderDataVo.getSubcontractingOrderNumber()));
            if (subcontractingOrder.getBackWeight() == 0) {
                subcontractingOrder.setBackWeight(updateSubcontractingOrderDataVo.getBackWeight());
            } else {
                BigDecimal add = new BigDecimal(String.valueOf(subcontractingOrder.getBackWeight())).add(new BigDecimal(String.valueOf(updateSubcontractingOrderDataVo.getBackWeight())));
                subcontractingOrder.setBackWeight(Double.parseDouble(add.toString()));
            }
            //当到货重量-退货重量≥委外重量，且关联的委外入库单状态为“已完成/已关结”时，委外订单状态更新为“已完成”
            BigDecimal subtract = new BigDecimal(String.valueOf(subcontractingOrder.getArrivedWeight())).subtract(new BigDecimal(String.valueOf(subcontractingOrder.getBackWeight())));
            double v = Double.parseDouble(subcontractingOrder.getSubcontractingWeight());
            if (Double.parseDouble(subtract.toString()) >= v) {
                if (updateSubcontractingOrderDataVo.getStatus() == 4 || updateSubcontractingOrderDataVo.getStatus() == 5) {
                    subcontractingOrder.setStatus(5);
                }
            }
            if (subcontractingOrder.getSubType() == 1) {
                //“委外入库重量”=委外订单中的“到货重量-退货重量”
                BackWeight backWeight = new BackWeight();
                backWeight.setSubcontractWeight(subcontractingOrder.getArrivedWeight());
                backWeight.setPlanCode(subcontractingOrder.getAssociatedDocNum());
                //回传排程计划及预排程委外入库重量
                schedulingPlanFeignService.planBack(backWeight);
            }

//           if (subcontractingOrder.getAssociatedDocNum()!=null){
//               SchedulingPlanDto planInfo = schedulingPlanFeignService.getPlanInfo(subcontractingOrder.getAssociatedDocNum());
//               if (planInfo!=null){
//                   BackDataVo backDataVo = new BackDataVo();
//                   backDataVo.setNetWeight(subcontractingOrder.getArrivedWeight());
//                   backDataVo.setMaterialCode(planInfo.getPlanMaterialCode());
//                   backDataVo.setSaleNumber(planInfo.getPlanAssociatedCode());
//                   boolean b = salesOrderMapper.updateSubWeight(backDataVo);
//               }
//           }


            return updateById(subcontractingOrder);
        }

        //修改单据到货重量
        if (updateSubcontractingOrderDataVo.getArriveWeight() != null) {
            SubcontractingOrder subcontractingOrder = subcontractingOrderMapper.selectOne(new QueryWrapper<SubcontractingOrder>().lambda().eq(SubcontractingOrder::getSubcontractingOrderNum, updateSubcontractingOrderDataVo.getSubcontractingOrderNumber()));
            if (subcontractingOrder.getArrivedWeight() == 0) {
                subcontractingOrder.setArrivedWeight(updateSubcontractingOrderDataVo.getArriveWeight());
            } else {
                BigDecimal add = new BigDecimal(String.valueOf(subcontractingOrder.getArrivedWeight())).add(new BigDecimal(String.valueOf(updateSubcontractingOrderDataVo.getArriveWeight())));
                subcontractingOrder.setArrivedWeight(Double.parseDouble(add.toString()));
            }
            //当到货重量-退货重量≥委外重量，且关联的委外入库单状态为“已完成/已关结”时，委外订单状态更新为“已完成”
            BigDecimal subtract = new BigDecimal(String.valueOf(subcontractingOrder.getArrivedWeight())).subtract(new BigDecimal(String.valueOf(subcontractingOrder.getBackWeight())));
            double v = Double.parseDouble(subcontractingOrder.getSubcontractingWeight());
            if (Double.parseDouble(subtract.toString()) >= v) {
                if (updateSubcontractingOrderDataVo.getStatus() == 4 || updateSubcontractingOrderDataVo.getStatus() == 5) {
                    subcontractingOrder.setStatus(5);
                }
            }
            if (subcontractingOrder.getSubType() == 1) {
                //“委外入库重量”=委外订单中的“到货重量-退货重量”
                BackWeight backWeight = new BackWeight();
                backWeight.setSubcontractWeight(updateSubcontractingOrderDataVo.getArriveWeight());
                backWeight.setPlanCode(subcontractingOrder.getAssociatedDocNum());
                //回传排程计划及预排程委外入库重量
                schedulingPlanFeignService.planBack(backWeight);
            }

            //通过委外计划单号查出排程的

//            if (subcontractingOrder.getAssociatedDocNum()!=null){
//                SchedulingPlanDto planInfo = schedulingPlanFeignService.getPlanInfo(subcontractingOrder.getAssociatedDocNum());
//                if (planInfo!=null){
//                    BackDataVo backDataVo = new BackDataVo();
//                    backDataVo.setNetWeight(subcontractingOrder.getArrivedWeight());
//                    backDataVo.setMaterialCode(planInfo.getPlanMaterialCode());
//                    backDataVo.setSaleNumber(planInfo.getPlanAssociatedCode());
//                    boolean b = salesOrderMapper.updateSubWeight(backDataVo);
//                }
//            }

            return updateById(subcontractingOrder);
        }
        return false;
    }

    /**
     * 委外入库回传委外订单（撤销 fegin调用）
     *
     * @param updateSubcontractingOrderDataVo
     */
    @Override
    public boolean updateSubcontractingOrderDataDelete(UpdateSubcontractingOrderDataVo updateSubcontractingOrderDataVo) {
        SubcontractingOrder subcontractingOrder = subcontractingOrderMapper.selectOne(new QueryWrapper<SubcontractingOrder>().lambda().eq(SubcontractingOrder::getSubcontractingOrderNum, updateSubcontractingOrderDataVo.getSubcontractingOrderNumber()));

        //修改明细对应出库量
        if (updateSubcontractingOrderDataVo.getOutWeight() != null) {
            //修改对应明细数据
            List<SubcontractingOrderMaterialDetail> subcontractingOrderDetails = subcontractingOrderMaterialDetailMapper.selectList(new QueryWrapper<SubcontractingOrderMaterialDetail>().lambda().eq(SubcontractingOrderMaterialDetail::getSubcontractingOrderId, subcontractingOrder.getId()));
            for (SubcontractingOrderMaterialDetail entity : subcontractingOrderDetails) {
                if (entity.getMaterialCode().equals(updateSubcontractingOrderDataVo.getMaterialCode())) {
                    if (entity.getOutWeight() == 0) {
                        entity.setOutWeight(updateSubcontractingOrderDataVo.getOutWeight());
                    } else {
                        BigDecimal add = new BigDecimal(String.valueOf(entity.getOutWeight())).subtract(new BigDecimal(String.valueOf(updateSubcontractingOrderDataVo.getOutWeight())));
                        entity.setOutWeight(Double.parseDouble(add.toString()));
                    }
                }
            }
            //修改生产排程和生产计划委外入库重量数据
            if (subcontractingOrder.getSubType() == 1) {
                //“委外入库重量”=委外订单中的“到货重量-退货重量”
                BackWeight backWeight = new BackWeight();
                backWeight.setSubcontractWeight(updateSubcontractingOrderDataVo.getArriveWeight());
                backWeight.setPlanCode(subcontractingOrder.getAssociatedDocNum());
                //回传排程计划及预排程委外入库重量
                schedulingPlanFeignService.planBackDelete(backWeight);
            }
            return subcontractingOrderMaterialDetailService.updateBatchById(subcontractingOrderDetails);
        }
        //修改单据退货重量
        if (updateSubcontractingOrderDataVo.getBackWeight() != null) {
            if (subcontractingOrder.getBackWeight() == 0) {
                subcontractingOrder.setBackWeight(updateSubcontractingOrderDataVo.getBackWeight());
            } else {
                BigDecimal add = new BigDecimal(String.valueOf(subcontractingOrder.getBackWeight())).subtract(new BigDecimal(String.valueOf(updateSubcontractingOrderDataVo.getBackWeight())));
                subcontractingOrder.setBackWeight(Double.parseDouble(add.toString()));
            }
            //当到货重量-退货重量≥委外重量，且关联的委外入库单状态为“已完成/已关结”时，委外订单状态更新为“已完成”
            BigDecimal subtract = new BigDecimal(String.valueOf(subcontractingOrder.getArrivedWeight())).subtract(new BigDecimal(String.valueOf(subcontractingOrder.getBackWeight())));
            double v = Double.parseDouble(subcontractingOrder.getSubcontractingWeight());
            if (Double.parseDouble(subtract.toString()) >= v) {
                if (updateSubcontractingOrderDataVo.getStatus() == 4 || updateSubcontractingOrderDataVo.getStatus() == 5) {
                    subcontractingOrder.setStatus(5);
                }
            }
            //修改生产排程和生产计划委外入库重量数据
            if (subcontractingOrder.getSubType() == 1) {
                //“委外入库重量”=委外订单中的“到货重量-退货重量”
                BackWeight backWeight = new BackWeight();
                backWeight.setSubcontractWeight(updateSubcontractingOrderDataVo.getArriveWeight());
                backWeight.setPlanCode(subcontractingOrder.getAssociatedDocNum());
                //回传排程计划及预排程委外入库重量
                schedulingPlanFeignService.planBackDelete(backWeight);
            }
            return updateById(subcontractingOrder);
        }

        //修改单据到货重量
        if (updateSubcontractingOrderDataVo.getArriveWeight() != null) {
            if (subcontractingOrder.getArrivedWeight() == 0) {
                subcontractingOrder.setArrivedWeight(updateSubcontractingOrderDataVo.getArriveWeight());
            } else {
                BigDecimal add = new BigDecimal(String.valueOf(subcontractingOrder.getArrivedWeight())).subtract(new BigDecimal(String.valueOf(updateSubcontractingOrderDataVo.getArriveWeight())));
                subcontractingOrder.setArrivedWeight(Double.parseDouble(add.toString()));
            }
            //当到货重量-退货重量≥委外重量，且关联的委外入库单状态为“已完成/已关结”时，委外订单状态更新为“已完成”
            BigDecimal subtract = new BigDecimal(String.valueOf(subcontractingOrder.getArrivedWeight())).subtract(new BigDecimal(String.valueOf(subcontractingOrder.getBackWeight())));
            double v = Double.parseDouble(subcontractingOrder.getSubcontractingWeight());
            if (Double.parseDouble(subtract.toString()) >= v) {
                if (updateSubcontractingOrderDataVo.getStatus() == 4 || updateSubcontractingOrderDataVo.getStatus() == 5) {
                    subcontractingOrder.setStatus(5);
                }
            }
            //修改生产排程和生产计划委外入库重量数据
            if (subcontractingOrder.getSubType() == 1) {
                //“委外入库重量”=委外订单中的“到货重量-退货重量”
                BackWeight backWeight = new BackWeight();
                backWeight.setSubcontractWeight(updateSubcontractingOrderDataVo.getArriveWeight());
                backWeight.setPlanCode(subcontractingOrder.getAssociatedDocNum());
                //回传排程计划及预排程委外入库重量
                schedulingPlanFeignService.planBackDelete(backWeight);
            }
            return updateById(subcontractingOrder);
        }
        return false;
    }

    /**
     * 委外退货回传委外订单
     *
     * @param updateSubcontractingOrderDataVo
     * @return
     */
    @Override
    public boolean updateBackOrderData(UpdateSubcontractingOrderDataVo updateSubcontractingOrderDataVo) {
        SubcontractingOrder subcontractingOrder = subcontractingOrderMapper.selectOne(new QueryWrapper<SubcontractingOrder>().lambda().eq(SubcontractingOrder::getSubcontractingOrderNum, updateSubcontractingOrderDataVo.getSubcontractingOrderNumber()));
        BigDecimal bigDecimal = new BigDecimal(String.valueOf(subcontractingOrder.getBackWeight()));
        BigDecimal bigDecimal1 = new BigDecimal(String.valueOf(updateSubcontractingOrderDataVo.getBackWeight()));
        BigDecimal add = bigDecimal.add(bigDecimal1);
        subcontractingOrder.setBackWeight(add.doubleValue());

        return updateById(subcontractingOrder);
    }

    /**
     * 委外退货回传委外订单
     *
     * @param updateSubcontractingOrderDataVo
     * @return
     */
    @Override
    public boolean updateBackOrderDataDelete(UpdateSubcontractingOrderDataVo updateSubcontractingOrderDataVo) {
        SubcontractingOrder subcontractingOrder = subcontractingOrderMapper.selectOne(new QueryWrapper<SubcontractingOrder>().lambda().eq(SubcontractingOrder::getSubcontractingOrderNum, updateSubcontractingOrderDataVo.getSubcontractingOrderNumber()));
        BigDecimal bigDecimal = new BigDecimal(String.valueOf(subcontractingOrder.getBackWeight()));
        BigDecimal bigDecimal1 = new BigDecimal(String.valueOf(updateSubcontractingOrderDataVo.getBackWeight()));
        BigDecimal add = bigDecimal.subtract(bigDecimal1);
        subcontractingOrder.setBackWeight(add.doubleValue());

        return updateById(subcontractingOrder);
    }

    /**
     * 委外订单新增查询bom明细数据及库存量
     *
     * @param bomId
     * @return
     */
    @Override
    public List<MaterialBomHalfDetailDto> getBomDetailList(long bomId) {
        AjaxResult ajaxResult = feignService.listDetailInventory(bomId);
        List<MaterialBomHalfDetailDto> bomDetailList = JSON.parseArray(JSON.toJSONString(ajaxResult.get("data")), MaterialBomHalfDetailDto.class);
        if (bomDetailList.size() > 0) {
            for (MaterialBomHalfDetailDto entity : bomDetailList) {
                //获取对应物料库存量
                double stockWeight = storageFegin.getStockWeight(entity.getMaterialCode());
                if (stockWeight == 0) {
                    entity.setStockWeight(0.0);
                } else {
                    entity.setStockWeight(stockWeight);
                }
                entity.setBomDetailDosage(entity.getBomProportion());
            }
        }
        return bomDetailList;
    }

    /**
     * 删除委外订单
     *
     * @param idStr
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteSubcontractingOrder(String idStr) {
        List<String> idList = Arrays.asList(idStr.split(","));
        if (idList.size() == 0) {
            throw new GlobalException("至少选择一条数据");
        }
        //获取勾选的委外订单
        List<SubcontractingOrder> subcontractingOrders = subcontractingOrderMapper.selectList(new QueryWrapper<SubcontractingOrder>().lambda().in(SubcontractingOrder::getId, idList));
        List<SubcontractingOrder> deleteList = new ArrayList<>();
        for (SubcontractingOrder entity : subcontractingOrders) {
            //待提交、订单未通过状态可删除
            if (entity.getStatus() == 1 || entity.getStatus() == 4) {
                deleteList.add(entity);
            }
        }
        if (deleteList.size() == 0) {
            throw new GlobalException("没有符合删除条件得数据");
        } else {
            return removeBatchByIds(deleteList);
        }
    }

    /**
     * 通过之后向委外出库和委外入库发送数据
     */
    @Transactional(rollbackFor = Exception.class)
    public void sendData(SubcontractingOrder subcontractingOrder) {
        //向委外入库发送数据
        SubcontractReceiptOtherVo subcontractReceiptOtherVo = new SubcontractReceiptOtherVo();
        //判断委外订单的物料是什么类型
        PublicGoods publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, subcontractingOrder.getMaterialCode()));
        if (publicGoods != null) {
            if (publicGoods.getMaterialCategory() == 3) {
                //半成品委外
                subcontractReceiptOtherVo.setSubcontractingType(2);
            }
            if (publicGoods.getMaterialCategory() == 4) {
                //成品委外
                subcontractReceiptOtherVo.setSubcontractingType(1);
            }
        }
        BeanUtils.copyProperties(subcontractingOrder, subcontractReceiptOtherVo);
        subcontractReceiptOtherVo.setSubcontractingWeight(subcontractingOrder.getSubcontractingWeight())
                .setConverterId(subcontractingOrder.getConverterId())
                .setMaterialCode(subcontractingOrder.getMaterialCode())
                .setSubcontractingOrderNum(subcontractingOrder.getSubcontractingOrderNum())
                .setMaterialType(String.valueOf(subcontractingOrder.getMaterialType()));
        try {
            storageFegin.addOther(subcontractReceiptOtherVo);
        } catch (Exception e) {
            throw new GlobalException("委外入库单生成失败");
        }
        //向委外出库发送数据
        List<SubcontractingOrderMaterialDetail> subcontractingOrderMaterialDetails = subcontractingOrderMaterialDetailMapper.selectList(new QueryWrapper<SubcontractingOrderMaterialDetail>().lambda()
                .eq(SubcontractingOrderMaterialDetail::getSubcontractingOrderId, subcontractingOrder.getId()));
        List<com.pureut.system.api.vo.SubcontractingOrderMaterialDetailVo> detailList = new ArrayList<>();
        if (subcontractingOrderMaterialDetails.size() != 0) {
            for (SubcontractingOrderMaterialDetail entity : subcontractingOrderMaterialDetails) {
                com.pureut.system.api.vo.SubcontractingOrderMaterialDetailVo subcontractingOrderMaterialDetailVo = new com.pureut.system.api.vo.SubcontractingOrderMaterialDetailVo();
                BeanUtils.copyProperties(entity, subcontractingOrderMaterialDetailVo);
                subcontractingOrderMaterialDetailVo.setSubcontractingOrderNum(subcontractingOrder.getSubcontractingOrderNum());
                subcontractingOrderMaterialDetailVo.setConverterId(subcontractingOrder.getConverterId());
                detailList.add(subcontractingOrderMaterialDetailVo);
            }
            subcontractReceiptOtherVo.setMaterialDetailList(detailList);
            try {
                storageFegin.addPickingOutsource(subcontractReceiptOtherVo);
            } catch (Exception e) {
                throw new GlobalException("委外出库单生成失败");
            }
        }

    }

}
